using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Admin3000.Backend.Api.Entity;
using System.Linq;


namespace Admin3000.Backend.Api
{
    [ApiController]
    [Route("[controller]")]
    public class UsersController
    {
        [HttpGet]
        public dynamic Get()
        {
            var users = GetUsers();
            return users;
        }
        [HttpGet("{id}")]
        public dynamic Get(int id)
        {
            var users = GetUsers();
            var user = users.Where(x => x.Id == id);

            return user;
        }
        [HttpPost]
        public dynamic Post(dynamic model)
        {
            return new { Code = 1000, Data = model, Msg = "创建用户成功" };
        }
        [HttpPut("{id}")]
        public dynamic Put(int id, dynamic model)
        {
            var users = GetUsers();
            return new
            {
                Code = 1000,
                Data = model,
                Msg = string.Format("您指定修改的用户的Id为:{0}, 已经修改成功", id)
            };
        }
        [HttpDelete("{id}")]
        public dynamic Delete(int id)
        {
            return new
            {
                Code = 1000,
                Msg = string.Format("指定id为: {0}的用户，删除成功，请注意查收消息", id)
            };
        }
        public IEnumerable<dynamic> GetUsers()
        {
            var users = new List<Users>
            {
                new Users{
                    Id = 1,
                    Username = "林伟强",
                    Password = "强维纳",
                },
                new Users{
                    Id = 2,
                    Username = "林伟强2",
                    Password = "强维纳2",
                },
                new Users{
                    Id = 3,
                    Username = "林伟强3",
                    Password = "强维纳3",
                },
            };
            return users;
        }
    }
}